﻿namespace GoodAdmin.System.Job
{
    /// <summary>
    /// 每次启动时，刷新接口资源
    /// </summary>
    [JobDetail("job_apiResource", Description = "刷新接口资源", GroupName = "default", Concurrent = false)]
    [PeriodSeconds(1, TriggerId = "trigger_apiResource", Description = "刷新接口资源", MaxNumberOfRuns = 1, RunOnStart = true)]
    public class MenuJob : IJob
    {
        private IRedisCacheManager _redisCacheManager;
        private readonly IMenuService _menuService;

        public MenuJob(IRedisCacheManager redisCacheManager,IMenuService menuService)
        {
            _redisCacheManager = redisCacheManager;
            _menuService = menuService;
        }
        public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
        {
            var key = CacheConst.ApiResource;
            _redisCacheManager.Remove(key);
            var resources = await Task.Run(() => _menuService.GetResource(), stoppingToken);
            _redisCacheManager.Set(key, resources);
        }
    }
}
